﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<link href="js-console.css" rel="stylesheet" />
	<!-- 2. Write a function that removes all elements with a given value
			var arr = [1,2,1,4,1,3,4,1,111,3,2,1,"1"];
			arr.remove(1); //arr = [2,4,3,4,111,3,2,"1"];
		* Attach it to the array class
		* Read about prototype and how to attach methods -->
</head>
<body>
	<div id="js-console"></div>
	<script src="js-console.js"></script>
	<script>
		// Add new prototype to Array
		Array.prototype.remove = function (element) {
			for (var i = 0; i < this.length; i++) {
				if (this[i] == element) {
					this.splice(i, 1);
				}
			}
		}

		// Construct the array and print
		var arr = new Array(1, 2, 1, 4, 1, 3, 4, 1, 111, 3, 2, 1, "1");
		jsConsole.writeLine("Source array");
		jsConsole.writeLine(arr.join());

		jsConsole.writeLine();

		// Use new extension function and print the new array
		arr.remove(1);
		jsConsole.writeLine("Array with removed element with value 1");
		jsConsole.writeLine(arr.join());
	</script>
</body>
</html>
